package admin

import (
	"duoke/service"
	"duoke/utils/gconv"
	"duoke/utils/request"
	"duoke/utils/response"
	"github.com/gin-gonic/gin"
)

var ShareOrder = new(shareOrderCtl)

type shareOrderCtl struct{}

func (ctl *shareOrderCtl) List(c *gin.Context) {
	req := request.JsonMap(c)
	orderId := gconv.String(req["order_id"])
	if orderId == "" {
		response.Error(c, "oorder_id缺失", nil)
		return
	}
	list, err := service.ShareOrder.List(c, orderId)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "", list)
}
func (ctl *shareOrderCtl) Del(c *gin.Context) {
	req := request.JsonMap(c)
	id := gconv.Int(req["id"])
	if id == 0 {
		response.Error(c, "ID缺失", nil)
		return
	}
	err := service.ShareOrder.Del(c, id)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "删除成功", nil)
}

func (ctl *shareOrderCtl) Retransmission(c *gin.Context) {
	req := request.JsonMap(c)
	orderId := gconv.String(req["order_id"])
	if orderId == "" {
		response.Error(c, "order_id缺失", nil)
		return
	}
	err := service.ShareOrder.Retransmission(c, orderId)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "分账成功", nil)
}
